package com.lxl.rabbitmq1.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {

    @Bean
    public FanoutExchange newsExchange() {//公司新闻交换机
//durable是否实例化持久化，autodelete是否自动删除
        FanoutExchange fanoutExchange = new FanoutExchange("news_fanout");

        return fanoutExchange;
    }

    @Bean
    public Queue itQueue() {//技术部新闻队列
        Queue queue = new Queue("it_news_queue");
        return queue;
    }

    @Bean
    public Queue marketQueue() {//市场部新闻队列
        Queue queue = new Queue("market_news_queue");
        return queue;
    }

    @Bean
    Binding bindingQueue1() {//绑定关系
        return BindingBuilder.bind(itQueue()).to(newsExchange());
    }

    @Bean
    Binding bindingQueue2() {//绑定关系
        return BindingBuilder.bind(marketQueue()).to(newsExchange());
    }

}